package com.miracle9.game.util;

import hirondelle.date4j.DateTime;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DateDifferenceProcess
{
  static final Logger cf = LoggerFactory.getLogger(DateDifferenceProcess.class);
  public static final TimeZone cg = TimeZone.getTimeZone("GMT+8");
  public static final String ch = "yyyy-MM-dd HH:mm:ss";
  public static final String ci = "yyyy-MM-dd";
  public static final String cj = "HH:mm:ss";
  
  public static boolean ifDate(String[] weekArray, String begin_date, String end_date, DateTime now)
  {
    if ((weekArray == null) || (weekArray.length == 0))
    {
      if (begin_date == null) {
        return false;
      }
      DateTime sDate = new DateTime(begin_date);
      DateTime eDate = new DateTime(end_date);
      if ((now.lteq(eDate)) && (sDate.lteq(now))) {
        return true;
      }
    }
    else
    {
      int day = now.getWeekDay().intValue();
      for (int i = 0; i < weekArray.length; i++)
      {
        cf.debug("week i==" + i + " ===" + weekArray[i] + " now day= " + day);
        if (day == Integer.parseInt(weekArray[i])) {
          return true;
        }
      }
      System.out.println("@@@@@@@day===" + now.toString());
      return false;
    }
    return false;
  }
  
  public static boolean isSameDayAs(long time1, long time2)
  {
    DateTime startTime = dateTime(time1);
    DateTime endTime = dateTime(time2);
    return startTime.isSameDayAs(endTime);
  }
  
  public static boolean isSameDayAs(long time)
  {
    DateTime now = k();
    DateTime endTime = dateTime(time);
    return now.isSameDayAs(endTime);
  }
  
  public static boolean ifDifference(long time1, long time2)
  {
    if ((time1 == 0L) || (time2 == 0L)) {
      return false;
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(time1);
    calendar.set(10, 0);
    calendar.set(12, 0);
    calendar.set(13, 0);
    calendar.set(14, 0);
    calendar.set(7, 1);
    long begin = calendar.getTimeInMillis();
    calendar.set(7, 7);
    long end = calendar.getTimeInMillis();
    if ((time2 >= begin) && (time2 <= end + 86400000L)) {
      return true;
    }
    return false;
  }
  
  public static boolean ifDifferencStatice(long time)
  {
    return ifDifference(time, k().getMilliseconds(cg));
  }
  
  public static boolean getDateInstance(String time1, String time2)throws ParseException
  {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(DateFormat.getDateInstance().parse(time1));
    int week1 = 3;
    calendar.setTime(DateFormat.getDateInstance().parse(time2));
    int week2 = 3;
    return week1 == week2;
  }
  
  public static int timeDifference(long time1, long time2)
  {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(time1);
    int week1 = 3;
    calendar.setTimeInMillis(time2);
    int week2 = 3;
    return week2 - week1;
  }
  
  public static int timeDifference(String time1, String time2)throws ParseException
  {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(DateFormat.getDateInstance().parse(time1));
    int week1 = 3;
    calendar.setTime(DateFormat.getDateInstance().parse(time2));
    int week2 = 3;
    return week2 - week1;
  }
  
  public static DateTime dateTime(long time)
  {
    DateTime dt = DateTime.forInstant(time, cg);
    return dt;
  }
  
  public static DateTime dateTime(String str)
  {
    return new DateTime(str);
  }
  
  public static DateTime k()
  {
    return DateTime.now(cg);
  }
  
  public static long getMilliseconds(DateTime dateTime)
  {
    return k().getMilliseconds(cg);
  }
  
  public static DateTime l()
  {
    return DateTime.today(cg);
  }
  
  public static int numDaysFrom(String start, String end)
  {
    DateTime startDate = dateTime(start);
    DateTime endDate = dateTime(end);
    int days = startDate.numDaysFrom(endDate);
    return days;
  }
  
  public static int numDaysFrom(Date begin)
  {
    return numDaysFrom(begin.getTime());
  }
  
  public static long staticDateTime(String time)
  {
    if ((time == null) || ("".equals(time))) {
      return 0L;
    }
    return dateTime(time).getMilliseconds(cg);
  }
  
  public static String getDate()
  {
    Date date = new Date();
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
    return sf.format(date);
  }
  
  public static String m()
  {
    Date date = new Date();
    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHH");
    return sf.format(date);
  }
  
  public static String getTime(long time)
  {
    Date date = new Date(time);
    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHH");
    return sf.format(date);
  }
  
  public static String n()
  {
    Date date = new Date();
    SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss");
    return sf.format(date);
  }
  
  public static String getDateYMDHMS(long time)
  {
    Date date = new Date(time);
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return sf.format(date);
  }
  
  public static String getDateYMD(long time)
  {
    Date date = new Date(time);
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
    return sf.format(date);
  }
  
  public static int numDaysFrom(long start, long end)
  {
    DateTime startDate = dateTime(start);
    DateTime endDate = dateTime(end);
    return startDate.numDaysFrom(endDate);
  }
  
  public static int numDaysFrom(long start)
  {
    DateTime startDate = dateTime(start);
    DateTime endDate = k();
    return startDate.numDaysFrom(endDate);
  }
  
  public static int interval(long start, long end)
  {
    long interval = end - start;
    int hour = (int)(interval / 1000L / 3600L);
    return hour;
  }
  
  public static Date dateFormat(String date, String format) throws ParseException
  {
    DateFormat dateFormat = new SimpleDateFormat(format);
    return dateFormat.parse(date);
  }
  
  public static Date dateFormat(String date) throws ParseException
  {
    return dateFormat(date, "yyyy-MM-dd HH:mm:ss");
  }
  
  public static String o()
  {
    String today = l().toString();
    String[] d = today.split("-");
    return d[0] + d[1];
  }
  
  public static String p()
  {
    String today = l().toString();
    String[] d = today.split("-");
    return d[0] + d[1] + d[2];
  }
  
  public static void main(String[] args)
  {
    System.out.println(m());
  }
}
